package com.hsoft.zhxy.app.xtgl_02_01.service.impl;


import com.hsoft.zhxy.app.xtgl_02_01.mapper.JcggYbmxMapper;
import com.hsoft.zhxy.app.common.model.entity.JcggYbmx;
import com.hsoft.zhxy.app.xtgl_02_01.service.JcggYbmxService;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.hsoft.zhxy.common.base.BaseService;
import com.hsoft.zhxy.common.result.ResultBody;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

 /**
 * All rights Reserved, Designed By 哈尔滨工业大学软件工程股份有限公司
 * 
 * @Title: 已办明细 Service层接口实现类
 * @Package 
 * @Description: 
 * @author: system
 * @date: 2020-10-26
 */
@Log4j2
@Service
public class JcggYbmxServiceImpl extends BaseService implements JcggYbmxService {

    @Autowired
    private JcggYbmxMapper jcggYbmxMapper;


    /**
     * 查询单条数据
     * @param jcggYbmx
     * @return
     */
    public JSONObject findOne(JcggYbmx jcggYbmx) {
        JcggYbmx rs = jcggYbmxMapper.selectOne(new QueryWrapper<JcggYbmx>().setEntity(jcggYbmx));
        return ResultBody.setData(rs);
    }


    /**
     * 查询列表数据
     * @param jcggYbmx
     * @return
     */
    public JSONObject findList(JcggYbmx jcggYbmx) {
        List<JcggYbmx> list = jcggYbmxMapper.selectList(new QueryWrapper<JcggYbmx>().setEntity(jcggYbmx));
        return ResultBody.setData(list);
    }


    /**
     * 查询分页数据
     * @param jcggYbmx
     * @param page
     * @param pageSize
     * @return
     */
    public JSONObject findListByPage(JcggYbmx jcggYbmx, long page, long pageSize) {

        Page<JcggYbmx> pageObj = new Page<JcggYbmx>(page, pageSize);
        IPage<JcggYbmx> result = jcggYbmxMapper.selectPage(pageObj, new QueryWrapper<JcggYbmx>().setEntity(jcggYbmx));

        return ResultBody.setData(result.getTotal(), result.getRecords());
    }


    /**
     * 新增
     * @param jcggYbmx
     * @return
     */
    public JSONObject add(JcggYbmx jcggYbmx) {
        jcggYbmx.setCjsj(LocalDateTime.now());
        jcggYbmx.setCjr(getYhid());
        jcggYbmx.setBgsj(LocalDateTime.now());
        jcggYbmx.setBgr(getYhid());
        return ResultBody.setData(jcggYbmxMapper.insert(jcggYbmx));
    }


    /**
     * 修改
     * @param jcggYbmx
     * @return
     */
    public JSONObject update(JcggYbmx jcggYbmx) {
        jcggYbmx.setBgsj(LocalDateTime.now());
        jcggYbmx.setBgr(getYhid());
        return ResultBody.setData(jcggYbmxMapper.updateById(jcggYbmx));
    }


    /**
     * 删除
     * @param jcggYbmx
     * @return
     */
    public JSONObject delete(JcggYbmx jcggYbmx) {
        return ResultBody.setData(jcggYbmxMapper.delete(new QueryWrapper<JcggYbmx>().setEntity(jcggYbmx)));
    }


}
